package structs

import (
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/reflect/protoreflect"
	"log"
)

type ResMessage struct {
	MsgId     int32
	ResCode   int32
	ProtoData []byte
	Callback  func()
}

func NewResMessageStruct(msgId int32, resCode int32, msg protoreflect.ProtoMessage) (ResMessage, bool) {
	protoData, err := proto.Marshal(msg)
	if err != nil {
		log.Println("msg Marshal err msgId:", msgId)
		return ResMessage{}, false
	}
	return ResMessage{
		MsgId:     msgId,
		ResCode:   resCode,
		ProtoData: protoData,
	}, true
}
func (resMsg ResMessage) GetMsgLen() int32 {
	//headlen+msgId+status+protodata
	return int32(len(resMsg.ProtoData))
}
